<?php
namespace Admin\Controller;
use Admin\Controller\BaseController;

class MyInformationController extends BaseController {

	public function index() {
		$studentId = I('session.uid');
		$student = D('Student')->where(array('id' => $studentId))->relation('class')->find();
		$this->assign('student', $student);
		$this->display();
	}

	public function changePassword() {
		if(!IS_POST) {
			$this->redirect('MyInformation/index');
		}
		$map['id'] = I('session.uid');
		$map['password'] = md5(I('post.old_password'));
		if(!M('Student')->where($map)->find()) {
			$this->error('旧密码有误！');
		}
		$data['id'] = $map['id'];
		$data['password'] = I('post.password');
		$data['repassword'] = I('post.repassword');
		$student = D('Student');
		if(!$student->create($data, 2)) {
			$this->error($student->getError());
		}
		if(false === $student->save()) {
			$this->error('更新学生信息失败！');
		}
		$this->success('修改成功！');
	}

}
